﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DOAN.Public;

namespace DOAN.DLL
{
    public class KhachHangDAL
    {
        ClsConnection cls;

        public KhachHangDAL()
        {
            cls = new ClsConnection();
        }

        public DataTable Load()
        {
            return cls.GetData("KHACHHANG_LOAD");
        }

        public int Insert(KhachHangPublic p)
        {
            int Nparameter = 15;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhachHang";
            name[1] = "@HoTenTenKhachHang";
            name[2] = "@HoTenNguoiDuocUyQuyen";
            name[3] = "@DienThoai";
            name[4] = "@CMND";
            name[5] = "@NgheNghiep";
            name[6] = "@ChucVu";
            name[7] = "@SoNhaDuong";
            name[8] = "@XaPhuong";
            name[9] = "@QuanHuyen";
            name[10] = "@TinhThanhPho";
            name[11] = "@Email";
            name[12] = "@TenDangNhap";
            name[13] = "@MatKhau";
            name[14] = "@KhachHang_Id";

            value[0] = p.MaKhachHang;
            value[1] = p.HoTenKhachHang;
            value[2] = p.HoTenNguoiDuocUyQuyen;
            value[3] = p.SoDienThoai;
            value[4] = p.CMND;
            value[5] = p.NgheNghiep;
            value[6] = p.ChucVu;
            value[7] = p.SoNhaDuong;
            value[8] = p.XaPhuong;
            value[9] = p.QuanHuyen;
            value[10] = p.TinhThanhPho;
            value[11] = p.Email;
            value[12] = p.TenDangNhap;
            value[13] = p.MatKhau;
            value[14] = p.KhachHang_Id;

            return cls.UpdateData("KHACHHANG_INSERT", name, value, Nparameter);
        }

        public int Update(KhachHangPublic p)
        {
            int Nparameter = 15;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhachHang";
            name[1] = "@HoTenTenKhachHang";
            name[2] = "@HoTenNguoiDuocUyQuyen";
            name[3] = "@DienThoai";
            name[4] = "@CMND";
            name[5] = "@NgheNghiep";
            name[6] = "@ChucVu";
            name[7] = "@SoNhaDuong";
            name[8] = "@XaPhuong";
            name[9] = "@QuanHuyen";
            name[10] = "@TinhThanhPho";
            name[11] = "@Email";
            name[12] = "@TenDangNhap";
            name[13] = "@MatKhau";
            name[14] = "@KhachHang_Id";

            value[0] = p.MaKhachHang;
            value[1] = p.HoTenKhachHang;
            value[2] = p.HoTenNguoiDuocUyQuyen;
            value[3] = p.SoDienThoai;
            value[4] = p.CMND;
            value[5] = p.NgheNghiep;
            value[6] = p.ChucVu;
            value[7] = p.SoNhaDuong;
            value[8] = p.XaPhuong;
            value[9] = p.QuanHuyen;
            value[10] = p.TinhThanhPho;
            value[11] = p.Email;
            value[12] = p.TenDangNhap;
            value[13] = p.MatKhau;
            value[14] = p.KhachHang_Id;

            return cls.UpdateData("KHACHHANG_UPDATE", name, value, Nparameter);
        }

        public int Delete(KhachHangPublic p)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhachHang";
            value[0] = p.MaKhachHang;
            return cls.UpdateData("KHACHHANG_DELETE", name, value, Nparameter);
        }
    }
}
